package services;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import com.utra.hellshan.upload.R;
import com.utra.hellshan.upload.OtherTools.SystemUtil;
import com.utra.hellshan.upload.UI.mapAvtivity;

public class StatusService extends Service {

    /**
     * 本service用于记录各种状态信息。目前记录登录状态，实例名
     *
     * 目前创建时必须要初始化的变量：Context
     *
     */

    public StatusServiceBinder statusServiceBinder = new StatusServiceBinder();
    private NotificationManager manager;
    private Notification notification;

    private static boolean loggedin = false ;       //记录是否登录
    private static long serviceID = 202605;         //serviceID
    private static String enityName = "default" ;   //实例名
    private static int count = 0 ;
    private static Context context;                 //产生地图的activity的context



    public static boolean GetLoginStatus()
    {
        Log.d("调用Service","从StatusService获取登录状态");
        return loggedin;
    }

    public static long getServiceID(){return serviceID;}

    public static String getEnityName() { return enityName; }

    public static void setContext(Context ctx){context = ctx;}

    public static void setLoggedin(boolean login){
        loggedin = login;
        Log.d("StatusService" , "设置登录状态:" + loggedin);
    }

    public static void setEntityName(String name){
        enityName = name;
        Log.d("i" , "更新实体名为:" + enityName);
    }


    @Override
    public void onCreate() {
        super.onCreate();
/*
        enityName = SystemUtil.getDeviceBrand();

        manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notification = new Notification.Builder(this)
                .setContentTitle("服务保活")
                .setContentText("请不要禁用此通知，以保持APP最大活性")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_launcher_foreground)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_foreground))
                .build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        manager.notify(1,notification);

*/

    }

    public StatusService() {
    }
    @Override
    public IBinder onBind(Intent intent) {
        return statusServiceBinder;
    }
    public class StatusServiceBinder extends Binder {
        StatusService getService(){return StatusService.this;}                  //调用该方法可以获得当前service的实例，以调用service中的方法
    }

}
